package com.fy56.platform.logistics.utils;

import com.fy56.platform.logistics.common.ResultModel;

import java.util.Map;

public class ParamUtil {

    /**
     * 获取Integer 转换值
     *
     * @param value
     * @return
     */
    public static String getStringValue(Object value){
        String result = "";
        try {
            if (value != null && StringUtil.isNotEmpty(value.toString())) {
                result = value.toString();
            }
        }catch (Exception ex){}
        return  result;
    }

    /**
     * 获取Integer 转换值
     *
     * @param value
     * @return
     */
    public static Integer getIntValue(Object value){
        Integer result = null;
        try {
            if (value != null) {
                result = Integer.parseInt(value.toString());
            }
        }catch (Exception ex){}
        return  result;
    }

    /**
     * 获取Double 转换值
     *
     * @param value
     * @return
     */
    public static Double getDoubleValue(Object value){
        Double result = null;
        try {
            if (value != null) {
                result = Double.parseDouble(value.toString());
            }
        }catch (Exception ex){}
        return  result;
    }

    /**
     * 将接口返回的Map对象转换为 ResultModel
     *
     * @param resultMap
     * @return
     */
    public static ResultModel getGmmsResultModel(Map<String, Object> resultMap){
        Integer code = 101;
        String message = "";
        Object objectContent  ="";
        if(resultMap != null && !resultMap.isEmpty()){
            Integer resultCode = getIntValue(resultMap.get("code"));
            Object resultState = resultMap.get("result");
            if((resultCode != null && resultCode ==100)){
                code = 100;
            }
            message =  resultMap.get("message") == null ? "" :  resultMap.get("message").toString();
            objectContent =  resultMap.get("resultObject") == null ? null :  resultMap.get("resultObject");
        }
        return new ResultModel(code, message, objectContent);
    }

}
